package com.freemarker.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/16 22:07
 * @since JDK 1.8
 */
@Controller
@RequestMapping(value = "/ftl")
public class FreeMarkerController {

    @RequestMapping(value = "/inde")
    public ModelAndView indexController() {
        Map<String, Object> data = new HashMap<>(2);
        data.put("name1", "YiHui Freemarker");
        data.put("now1", "");
        return new ModelAndView("Demo2", data);
    }

    @RequestMapping("/index/{page}")
    public String requestController(@PathVariable("page")String page, ModelMap modelMap){
        modelMap.put("res","这是res配置的值");
        return page;
    }


    @RequestMapping(value = "/{path:[0-9A-Za-z]+}/{id:[0-9]+}_{page:[0-9]+}.jhtml",method = RequestMethod.GET)
    public String requestModelController(@PathVariable("path")String path,@PathVariable("id")Integer id,@PathVariable("page")String page){
        System.out.println(path+"id"+id+"page"+page);
        Map map = new HashMap();
        map.put("key","222");
        return "Demo2";
    }

}
